def is_prime(n):
    if n == 1:
        return False

    d = 2

    while d * d <= n and n % d != 0:
        d += 1

    return d * d > n


def wrong_input():
    print("Wrong input")
    exit()


numbers = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
}

words = input().split()
n = 0

for word in words:
    number = numbers.get(word)

    if number is None:
        wrong_input()

    n = n * 10 + number

if n < 100 or n > 999:
    wrong_input()

for i in range(1000):
    if is_prime(n - i):
        print(n - i)
        break

    if is_prime(n + i):
        print(n + i)
        break
